package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.AttrKey;
import com.atguigu.lease.model.entity.AttrValue;
import com.atguigu.lease.web.admin.mapper.AttrKeyMapper;
import com.atguigu.lease.web.admin.mapper.AttrValueMapper;
import com.atguigu.lease.web.admin.service.AttrKeyService;
import com.atguigu.lease.web.admin.vo.attr.AttrKeyVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class AttrKeyServiceImpl extends ServiceImpl<AttrKeyMapper, AttrKey>
    implements AttrKeyService{
@Autowired
private AttrKeyMapper attrKeyMapper;
@Autowired
private AttrValueMapper attrValueMapper;
    @Override
    public List<AttrKeyVo> forlist() {
        List<AttrKeyVo> list = new ArrayList<>();
        List<AttrKey> attrKeys = attrKeyMapper.selectList(null);
        for (AttrKey attrKey : attrKeys) {
            AttrKeyVo attrKeyVo = new AttrKeyVo();
            BeanUtils.copyProperties(attrKey,attrKeyVo);
            LambdaQueryWrapper<AttrValue> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AttrValue::getAttrKeyId,attrKey.getId());
            List<AttrValue> attrValues = attrValueMapper.selectList(queryWrapper);
            attrKeyVo.setAttrValueList(attrValues);
            list.add(attrKeyVo);
        }
        return list;
    }
}




